Production: Add Stack Name to our Application

We will add the stack name to our Hello World application in this lesson so that our application will know what environment it is running in.

Objective#

  • Create separate environments for staging.

Steps#

  • Adding the stack name to our Hello World application.

In the real world, we will generally want to have at least one environment to test our application and infrastructure before rolling changes out to production. A common model is to call the testing environment ‘staging’ and production ‘prod’. We’ll set these up next.

In this and upcoming two lessons, we will decommission our existing infrastructure and replace it with two CloudFormation nested stacks representing our staging and prod environments. We will also update our CodePipeline so that it will promote updates to prod only after they’ve successfully passed through staging.

Adding the stack name to Hello World#

Let’s start by making a small change to the start-service.sh script so that our application will know what environment it is running in.

start-service.sh

Then, we also need to update the start script in package.json to pass the stack name environment variable to the application.

package.json

Now, let’s change the response in server.js to include the stack name.

server.js

Let’s push these changes to GitHub.

terminal

Finally, let’s wait for the changes to go through the pipeline, and we should see our stack name when we hit our application’s endpoint.

terminal

Now in the next lesson, we will create our nested stack for staging.

Scaling: Remove Instances
Production: Create Staging Stack
Mark as Completed
Report an Issue